package com.dries.security.core.enums;

import com.dries.security.common.exception.ApiException;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Stream;

/**
 * @Description:
 * @Author ZSY
 * @createTime 2020/9/4 11:11
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum LoginType {

    REDIRECT(0, "跳转"),
    JSON(1, "JSON")
    ;

    private Integer code;
    private String description;

    /**
     * 根据ID获取当前枚举
     * @param code
     * @return
     */
    public static LoginType getLoginTypeByCode(Integer code) {

        Objects.requireNonNull(code);
        return Stream.of(values())
                .filter(e -> e.getCode().equals(code))
                .findAny()
                .orElseThrow(() -> new IllegalStateException(code + "not exists"));
    }

}
